import { defineConfig, loadEnv } from 'vite';
import react from '@vitejs/plugin-react';
import { createHtmlPlugin } from 'vite-plugin-html';
import svgr from "vite-plugin-svgr";
import path from "path";

// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
    let env = loadEnv(mode, process.cwd());

    return ({
        base: env.VITE_BASEDIR || '/',
        plugins: [
            react(),
            svgr(),
        ],
        server: {
            hmr: false,
            host: '0.0.0.0',
            port: 5001,
            proxy: {
                '/api': {
                    // target: ' http://127.0.0.1:8082',
                    target: 'http://www.menibymeni.com',
                    changeOrigin: true,
                    rewrite: (path) => path.replace(/^\/api/, ''),
                },
            },
        },
        resolve: {
            alias: {
                "@": path.resolve(__dirname, "src"),
            }
        },
        define: {
            BASEDIR: JSON.stringify(env.VITE_BASEDIR),
            DEBUG: env.VITE_DEBUG,
            WEB_NAME: JSON.stringify(env.VITE_WEB_NAME),
            WEB_TITLE: JSON.stringify(env.VITE_WEB_TITLE),
            AES_KEY: JSON.stringify(env.VITE_AES_KEY),
            API_PREFIX: JSON.stringify(env.VITE_API_PREFIX),
            RESPONSE_SUCCESS_CODE: env.VITE_RESPONSE_SUCCESS,
        },
    });
});
